<template>
  <!-- 相关检查 -->
    <el-form inline size="mini">
      <el-row class="bg-row">
        <el-form-item label="验光号">
          <el-input  v-model="checkData.checkNumber" readonly></el-input>
        </el-form-item>
        <el-form-item label="验光师">
          <el-input  v-model="checkData.checker" readonly></el-input>
        </el-form-item>
        <el-form-item label="日期">
          <el-input  v-model="checkData.checkDate" readonly></el-input>
        </el-form-item>
      </el-row>
      <el-row class="bg-row">
        <el-form-item label="卡号" v-if="customerData.cardNum">
          <el-input v-model="customerData.cardNum" @keyup.enter.native="getCustomerByCardNo()"></el-input>
        </el-form-item>
        <el-form-item label="卡号" v-else>
          <el-input v-model="customerData.uniqueCode"></el-input>
        </el-form-item>
        <!-- <el-form-item label-width="0">
          <el-button type="primary" icon="el-icon-search" @click="openDialog('customer')">查询</el-button>
        </el-form-item> -->
        <el-form-item label="姓名">
          <el-input class="width-125"  v-model="customerData.name" readonly></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-input class="width-125" v-if="customerData.gender == 0" value="男" readonly></el-input>
          <el-input class="width-125" v-if="customerData.gender == 1" value="女" readonly></el-input>
        </el-form-item>
        <el-form-item label="生日">
          <el-input class="width-125"  v-model="customerData.birthDay" readonly></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input class="width-125"  v-model="customerData.telPhone" readonly></el-input>
        </el-form-item>
        <!-- <el-form-item label-width="0">
          <el-button type="primary" icon="el-icon-collection" @click="openDialog('customerDetail')">详情</el-button>
        </el-form-item> -->
      </el-row>
      <el-divider content-position="left">特殊功能检查</el-divider>
      <!-- <el-row class="bg-row"> -->
        <table class="miui-table">
          <tr>
            <td width="50px"></td>
            <td>眼轴</td>
            <td>前房深</td>
            <td>晶状体厚度</td>
            <td>玻璃体腔长度</td>
            <td>角膜直径</td>
          </tr>
          <tr>
            <td>OD</td>
            <td><el-input v-model="dataForm.eyeAxisOd"><template slot="append">mm</template></el-input></td>
            <td><el-input v-model="dataForm.anteriorChamberDeepOd"><template slot="append">mm</template></el-input></td>
            <td><el-input v-model="dataForm.lensThicknessOd"><template slot="append">mm</template></el-input></td>
            <td><el-input v-model="dataForm.vitreousCavityLengthOd"><template slot="append">mm</template></el-input></td>
            <td><el-input v-model="dataForm.corneaDiameterOd"><template slot="append">mm</template></el-input></td>
          </tr>
          <tr>
            <td>OS</td>
            <td><el-input v-model="dataForm.eyeAxisOs"><template slot="append">mm</template></el-input></td>
            <td><el-input v-model="dataForm.anteriorChamberDeepOs"><template slot="append">mm</template></el-input></td>
            <td><el-input v-model="dataForm.lensThicknessOs"><template slot="append">mm</template></el-input></td>
            <td><el-input v-model="dataForm.vitreousCavityLengthOs"><template slot="append">mm</template></el-input></td>
            <td><el-input v-model="dataForm.corneaDiameterOs"><template slot="append">mm</template></el-input></td>
          </tr>
        </table>
      <!-- </el-row> -->
      <!-- <el-row class="bg-row" style="margin-top: 20px;"> -->
        <table class="miui-table">
          <tr>
            <td width="50px"></td>
            <td>角膜厚度</td>
            <td>角膜曲率(SK)</td>
            <td>角膜曲率(FK)</td>
          </tr>
          <tr>
            <td>OD</td>
            <td><el-input v-model="dataForm.cornealThicknessOd"><template slot="append">mm</template></el-input></td>
            <td>
              <el-row>
                <el-col :span="11"><el-input v-model="dataForm.corneaCurvatureOds1"></el-input></el-col>
                <el-col :span="2" style="text-align: center;">@</el-col>
                <el-col :span="11"><el-input v-model="dataForm.corneaCurvatureOds2"></el-input></el-col>
              </el-row>
            </td>
            <td>
              <el-row>
                <el-col :span="11"><el-input v-model="dataForm.corneaCurvatureOdf1"></el-input></el-col>
                <el-col :span="2" style="text-align: center;">@</el-col>
                <el-col :span="11"><el-input v-model="dataForm.corneaCurvatureOdf2"></el-input></el-col>
              </el-row>
            </td>
          </tr>
          <tr>
            <td>OS</td>
            <td><el-input v-model="dataForm.cornealThicknessOd"><template slot="append">mm</template></el-input></td>
            <td>
              <el-row>
                <el-col :span="11"><el-input v-model="dataForm.corneaCurvatureOds1"></el-input></el-col>
                <el-col :span="2" style="text-align: center;">@</el-col>
                <el-col :span="11"><el-input v-model="dataForm.corneaCurvatureOds2"></el-input></el-col>
              </el-row>
            </td>
            <td>
              <el-row>
                <el-col :span="11"><el-input v-model="dataForm.corneaCurvatureOdf1"></el-input></el-col>
                <el-col :span="2" style="text-align: center;">@</el-col>
                <el-col :span="11"><el-input v-model="dataForm.corneaCurvatureOdf2"></el-input></el-col>
              </el-row>
            </td>
          </tr>
        </table>
      <!-- </el-row> -->
      <!-- <el-row class="bg-row" style="margin-top: 20px;"> -->
        <table class="miui-table">
          <tr>
            <td :colspan="7">角膜地形图</td>
            <td :colspan="3">泪膜检测</td>
          </tr>
          <tr>
            <td width="50px"></td>
            <td>SK</td>
            <td>FK</td>
            <td>AST</td>
            <td>E值</td>
            <td>SAI</td>
            <td>SRI</td>
            <td>分级</td>
            <td>schirme5</td>
            <td>BUT</td>
          </tr>
          <tr>
            <td>OD</td>
            <td><el-input v-model="dataForm.topographySkOd"></el-input></td>
            <td><el-input v-model="dataForm.topographyFkOd"></el-input></td>
            <td><el-input v-model="dataForm.topographyAstOd"></el-input></td>
            <td><el-input v-model="dataForm.topographyeOd"></el-input></td>
            <td><el-input v-model="dataForm.topographySaiOd"></el-input></td>
            <td><el-input v-model="dataForm.topographySriOd"></el-input></td>
            <td><el-input v-model="dataForm.tearFilmGradeOd1"></el-input></td>
            <td><el-input v-model="dataForm.schirme5Od"><template slot="append">mm</template></el-input></td>
            <td><el-input v-model="dataForm.butOd"><template slot="append">s</template></el-input></td>
          </tr>
          <tr>
            <td>OS</td>
            <td><el-input v-model="dataForm.topographySkOs"></el-input></td>
            <td><el-input v-model="dataForm.topographyFkOs"></el-input></td>
            <td><el-input v-model="dataForm.topographyAstOs"></el-input></td>
            <td><el-input v-model="dataForm.topographyeOs"></el-input></td>
            <td><el-input v-model="dataForm.topographySaiOs"></el-input></td>
            <td><el-input v-model="dataForm.topographySriOs"></el-input></td>
            <td><el-input v-model="dataForm.tearFilmGradeOs1"></el-input></td>
            <td><el-input v-model="dataForm.schirme5Os"><template slot="append">mm</template></el-input></td>
            <td><el-input v-model="dataForm.butOs"><template slot="append">s</template></el-input></td>
          </tr>
        </table>
      <!-- </el-row> -->
      <el-divider content-position="left">角膜内皮细胞计数检查</el-divider>
      <!-- <el-row class="bg-row" style="margin-top: 20px;"> -->
        <table class="miui-table">
          <tr>
            <td width="50px"></td>
            <td>细胞密度</td>
            <td>平均细胞面积</td>
            <td>六边形细胞比例</td>
            <td>变异系数</td>
            <td>动态检影检查AST</td>
          </tr>
          <tr>
            <td>OD</td>
            <td><el-input v-model="dataForm.thicknessOd"><template slot="append">个/mm²</template></el-input></td>
            <td><el-input v-model="dataForm.areaOd"><template slot="append">um²</template></el-input></td>
            <td><el-input v-model="dataForm.scaleOd"><template slot="append">%</template></el-input></td>
            <td><el-input v-model="dataForm.variationOd"><template slot="append">%</template></el-input></td>
            <td><el-input v-model="dataForm.dynamicAdjustmentOd"></el-input></td>
          </tr>
          <tr>
            <td>OS</td>
            <td><el-input v-model="dataForm.thicknessOs"><template slot="append">个/mm²</template></el-input></td>
            <td><el-input v-model="dataForm.areaOs"><template slot="append">um²</template></el-input></td>
            <td><el-input v-model="dataForm.scaleOs"><template slot="append">%</template></el-input></td>
            <td><el-input v-model="dataForm.variationOs"><template slot="append">%</template></el-input></td>
            <td><el-input v-model="dataForm.dynamicAdjustmentOs"></el-input></td>
          </tr>
        </table>
        <div style="position: fixed;bottom: 0;left: 0;right: 0;height: 45px;background-color: #d2d9db;display: flex;align-items: center;justify-content: flex-end;padding: 0 40px;">
          <el-button type="primary" @click="refractiveFormSubmit" v-prevent-re-click>保 存</el-button>
        </div>
        <!-- <el-row style="margin: 15px auto;text-align: center;">
          <el-button type="primary" @click="refractiveFormSubmit" v-prevent-re-click>保 存</el-button>
        </el-row> -->
        <!-- 弹窗，查询顾客 -->
        <search-customer v-if="searchCustomerVisible" ref="searchCustomer" @refreshForm="getCustomerData"></search-customer>
        <!-- 弹窗，顾客详情 -->
        <detail-customer v-if="detailCustomerVisible" ref="detailCustomer"></detail-customer>
      <!-- </el-row> -->
    </el-form>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { filterParams } from '@/util/tools'
	import { addChkOptometryBasic, saveHealthCheckData, getHealthCheck } from '@/api/admin/optometry/optometry'

  import SearchCustomer from '@/components/business/customer-search' // 查询顾客
  import DetailCustomer from '@/views/eims/customer/detail' // 顾客详情
  export default {
    data() {
      return {
        visible: false,
        activeName: 'fourth',
				id: '',
        searchCustomerVisible: '',
        detailCustomerVisible: '',
        checkData: {
          checkNumber: '',
          checker: '',
          checkDate: ''
        },
        dataForm:{},
        chkDatas:[],
        customerData: {},
        checkList: [],
        optType: '',
        optOptions: [
          { value: '1', label: '远用' },
          { value: '2', label: '近用' },
          { value: '3', label: '渐进/双光' },
          { value: '4', label: '隐形' },
          { value: '5', label: '中用' },
          { value: '6', label: '角膜塑形' },
          { value: '7', label: '视觉训练' },
        ]
      }
    },
    components: {
      SearchCustomer,
      DetailCustomer
    },
    computed: {
      ...mapGetters(['permissions', 'bizData', 'userInfo', 'isCollapse'])
    },
    methods: {
      init(data) {
        this.visible = true
        this.checkData = data.checkData
        this.customerData = data.customer
				this.id = data.id
        for(let key in this.dataForm){
          this.dataForm[key] = ''
        }
				this.$nextTick(() => {
					if(this.id){
						getHealthCheck(this.id).then(result => {
							let resultData = result.data.data
							if(resultData){
								this.dataForm = resultData
							}
						})
					}
				})
      },
      //  打开弹窗
      openDialog(name) {
        switch (name) {
          case 'customer':
            this.searchCustomerVisible = true
            this.$nextTick(() => {
              this.$refs.searchCustomer.init()
            })
            break;
          case 'customerDetail':
            this.detailCustomerVisible = true
            this.$nextTick(() => {
              this.$refs.detailCustomer.init(this.customerData.id, '会员详细')
            })
            break;
        }
      },
      //  获取客户信息
      getCustomerData(data) {
        this.customerData = data
      },
      //  保存相关检查数据
      refractiveFormSubmit() {
        let params1 = {
          chkNumber: this.checkData.checkNumber,
          customerId: this.customerData.id,
          customerName: this.customerData.name,
          personId: this.customerData.personId
        }
        if(!this.id){
          addChkOptometryBasic(params1).then(result => {
            this.id = result.data.data
            this.$emit('addBasic',result.data.data)
          })
        }else{
          this.$emit('addBasic',this.id)
        }
      },
      saveRefractive(data){
        let params1 = {
          optometryBasicId: data,
          customerId: this.customerData.id,
          chkNumber: this.checkData.checkNumber
        }
        let params2 = filterParams(this.dataForm)
        saveHealthCheckData(Object.assign(params1,params2)).then(result => {
          if(result.data.data){
            this.$message.success('相关检查保存成功')
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .bg-row {
    // background-color: #cadee8;
    padding-left: 15px;
    padding-top: 5px;
  }
  .width-125 {
    width: 125px;
  }
  .miui-table {
    width: 100%;
    margin: 10px 0;
    background-color: #b1e2ec3b;
    tr th {
      background-color: #f4f5f7;
    }

    tr th, tr td {
      padding: 10px 8px;
      border: solid 1px #e7e7e7;
      text-align: center;
    }
    .miui-table-header td{
      background-color: #7898a8;
      color: #fff;
    }
    .miui-table-tbody{
      background-color: #cadee8;
    }
  }
</style>
